package com.cn.jinl.controller;


import com.cn.jinl.api.IOnDutyProductService;
import com.cn.jinl.domain.OnDutyProduct;
import com.cn.jinl.domain.OnDutyProductBanVo;
import com.cn.jinl.domain.OnDutyWeek;
import com.cn.jinl.domain.ProductStorageRelate;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dutyprod")
public class OnDutyProductController {

    @Autowired
    private IOnDutyProductService onDutyProductService;


    @RequestMapping("/getOnDutyProductList/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,List<OnDutyProduct>>> getOnDutyProductList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,List<OnDutyProduct>>> response = new JsonResponse<>();
        Map<String,List<OnDutyProduct>> onDutyProducts = onDutyProductService.getOnDutyProductList(queryForm);
        response.setResult(onDutyProducts);
        response.setSuccess(true);
        return response;
    }

    //当班机台
    @RequestMapping("/getOnDutyProductBanList/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,OnDutyProductBanVo>> getOnDutyProductBanList( @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,OnDutyProductBanVo>> response = new JsonResponse<>();
        Map<String, OnDutyProductBanVo> onDutyProducts = onDutyProductService.getOnDutyProductBanList();
        response.setResult(onDutyProducts);
        response.setSuccess(true);
        return response;
    }

    //当班个人
    @RequestMapping("/getOnDutyProductPersonList/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,OnDutyProductBanVo>> getOnDutyProductPersonList( @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,OnDutyProductBanVo>> response = new JsonResponse<>();
        Map<String, OnDutyProductBanVo> onDutyProducts = onDutyProductService.getOnDutyProductPersonList();
        response.setResult(onDutyProducts);
        response.setSuccess(true);
        return response;
    }


    //查看生产记录
    @RequestMapping("/getOnDutyProductsByPlanId/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductStorageRelate>> getOnDutyProductsByPlanId(String planId, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<ProductStorageRelate>> response = new JsonResponse<>();
        List<ProductStorageRelate> results = onDutyProductService.getOnDutyProductsByPlanId(planId);
        response.setResult(results);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getOnDutyProductsByDutyDay/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OnDutyProduct>> getOnDutyProductsByDutyDay(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<OnDutyProduct>> response = new JsonResponse<>();
        List<OnDutyProduct> onDutyProducts = onDutyProductService.getOnDutyProductsByDutyDay(queryForm);
        response.setResult(onDutyProducts);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/addBatchOnDutyProduct/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addBatchOnDutyProduct(@RequestBody List<OnDutyProduct> onDutyProducts, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyProductService.addBatchOnDutyProduct(onDutyProducts);
        return CommonUtil.getResponseData(response,result);
    }

    //获取whiteDay dutyDay
    @RequestMapping("/getOnDutyAndWhiteDay/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,String>> getOnDutyAndWhiteDay( @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,String>> response = new JsonResponse<>();
        Map<String, String> dutyMap = onDutyProductService.getOnDutyAndWhiteDay();
        response.setResult(dutyMap);
        response.setSuccess(true);
        return response;
    }


    //扫码报工 扫设备码
    @RequestMapping("/api/getScanOnDutyProductByDeviceCode")
    @ResponseBody
    public JsonResponse<OnDutyProduct> getScanOnDutyProductByDeviceCode(String deviceCode) throws Exception{
        JsonResponse<OnDutyProduct> response = new JsonResponse<>();
        OnDutyProduct result = onDutyProductService.getScanOnDutyProductByDeviceCode(deviceCode);
        if(null == result){
            response.setSuccess(false);
            response.setMessage("未查询到任务计划！");
        }else{
            response.setResult(result);
            response.setSuccess(true);
        }
        return response;
    }


    //首页获取本班生产
    @RequestMapping("/api/getOnDutyRunningProduct")
    @ResponseBody
    public JsonResponse<Map<String, Integer>> getOnDutyRunningProduct() throws Exception{
        JsonResponse<Map<String,Integer>> response = new JsonResponse<>();
        Map<String,Integer> result = onDutyProductService.getOnDutyRunningProduct();
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    //首页获取产线动态
    @RequestMapping("/api/getOnDutyProductDetail")
    @ResponseBody
    public JsonResponse<Map<String,Object>> getOnDutyProductDetail() throws Exception{
        JsonResponse<Map<String,Object>> response = new JsonResponse<>();
        Map<String,Object> result = onDutyProductService.getOnDutyProductDetail();
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

}
